﻿using System;
using System.Collections.Generic;
using System.Text;
using DBScript;
using eBlog.Entity;
namespace eBlog.Service
{
    public class UserService
    {

       /// <summary>
       /// add user 
       /// </summary>
       /// <param name="user">user model</param>
       /// <returns>user'id</returns>
       public static int AddUser(User user)
       {
          IDBBase dal = DBFactory.GetDbProvider();
          return  dal.Add(user);
       }

       /// <summary>
       /// get user'model by user id
       /// </summary>
       /// <param name="id">user id</param>
       /// <returns>user'model</returns>
       public static User GetUserById(int id)
       {
           IDBBase dal = DBFactory.GetDbProvider();
           return dal.GetModel<User>(id);
       }
        /// <summary>
        /// get user'model by user'name
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
       public static User GetUserByName(string userName)
       {
           IDBBase dal = DBFactory.GetDbProvider();
           User user= dal.Where("LoginName=@uname").SetString("uname", userName).GetModel<User>();
           return user;
       }
        /// <summary>
        /// get user list
        /// </summary>
        /// <returns></returns>
        public static List<User> GetUserList()
        {
            IDBBase dal = DBFactory.GetDbProvider();
            return dal.GetList<User>();
        }

        /// <summary>
        /// update user
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
       public static bool UpdateUser(User user)
       {
           IDBBase dal = DBFactory.GetDbProvider();
           return dal.Update(user);
        }

    }
}
